package com.duowan.realtime.thrift;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TBinaryProtocol.Factory;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.server.TThreadPoolServer.Args;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.duowan.realtime.thirft.api.BloomFilterService;
import com.duowan.realtime.thirft.api.Constants;
import com.duowan.realtime.thirft.api.BloomFilterService.Iface;

public class BloomFilterServer {

	private static final Logger LOG = LoggerFactory.getLogger("bflog");
	private static int port = Constants.DEFAULT_BF_SERVER_PORT;
	
	public static void main(String[] args) throws TTransportException {
		//String serverIp = args[0];
		// 设置服务端口
		TServerSocket serverTransport = new TServerSocket(port);
		// 设置协议工厂
		Factory proFactory = new TBinaryProtocol.Factory();
		TProcessor processor = new BloomFilterService.Processor<Iface>(new BloomFilterServiceImpl());
		Args params = new Args(serverTransport);
		params.inputProtocolFactory(proFactory);
		params.processor(processor);
		TServer server = new TThreadPoolServer(params);
		LOG.info("Start server on port:" + port);
		server.serve();
	}
	
}
